package com.sk.sourcecircle.activity.main;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;

import com.hyphenate.chat.EMClient;
import com.sk.sourcecircle.R;


/**
 * Created by Administrator on 2017/10/24.
 */

public class WelcomeActivity extends AppCompatActivity {


    private boolean isFirstIn;

    @Override
    protected void onCreate(@Nullable final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        setTranslucent(this);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏

        final SharedPreferences perPreferences = getSharedPreferences("dajia", MODE_PRIVATE);
        isFirstIn = perPreferences.getBoolean("isFirstIn", true);
        Handler handler = new Handler();
        if(!isFirstIn){
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    EMClient.getInstance().groupManager().loadAllGroups();
                    EMClient.getInstance().chatManager().loadAllConversations();
                    Intent intent = new Intent(WelcomeActivity.this,MainActivity.class);
                    startActivity(intent);
                    finish();
                }
            },1500);
        }else {
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    perPreferences.edit().putBoolean("isFirstIn",false).apply();
                    Intent intent = new Intent(WelcomeActivity.this,ViewPagerActivity.class);
                    startActivity(intent);
                    finish();
                }
            },1500);
        }

    }

    public static void setTranslucent(Activity activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            // 设置状态栏透明
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }

}
